package com.pengcheng.taskapplication.mvp.view.activity;

import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.contants.ConstantValue;
import com.pengcheng.taskapplication.model.IcbcverifySms;
import com.pengcheng.taskapplication.mvp.presenter.UserPresenter;
import com.pengcheng.taskapplication.net.IView;
import com.pengcheng.taskapplication.util.SPUtils;
import com.pengcheng.taskapplication.util.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ZFT on 2020/10/27.
 */

public class ICBCCardActivity extends BaseActivity implements IView{
    private String bankcardCode;
    private String smsNo;
    private long certId;
    @BindView(R.id.tv_bank_code)
    TextView tv_bank_code;
    @BindView(R.id.et_code)
    EditText et_code;
    private long from;

    private UserPresenter userPresenter;

    @Override
    protected int layoutResID() {
        return R.layout.activity_e_bank_layout;
    }

    @Override
    protected void initData() {
        userPresenter=new UserPresenter(this);
        from =getIntent().getLongExtra("from",0);
        bankcardCode=getIntent().getStringExtra("bankcardCode");
        smsNo=getIntent().getStringExtra("smsNo");
        certId=getIntent().getLongExtra("certId",0);
        tv_bank_code.setText(bankcardCode);

    }

    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        if(actionType.equals(ConstantValue.RequestKey.verifySms)){
            if(from==0){
                Intent intent = new Intent(context, ApplyActivity.class);
                startActivity(intent);
                ICBCCardActivity.this.finish();
            }else if(from==1) {
                Intent intent = new Intent(context, MyBankList.class);
                startActivity(intent);
                ICBCCardActivity.this.finish();
            }
        }
    }

    @Override
    public void onFailed(String code, String msg) {
        ToastUtils.showShortToast(msg);
    }
    @OnClick({R.id.img_back,R.id.tv_apply})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.tv_apply:
                String codeStr= et_code.getText().toString().trim();
                if(codeStr==null||codeStr.length()==0){
                    ToastUtils.showShortToast("请输入手机验证码");
                    return;
                }
                IcbcverifySms icbcverifySms=new IcbcverifySms();
                icbcverifySms.setCertId(certId);
                icbcverifySms.setSmsNo(smsNo);
                icbcverifySms.setSmsCode(codeStr);
                verifySms(icbcverifySms);
                break;
        }
    }

    public void verifySms(IcbcverifySms icbcverifySms){
        userPresenter.verifySms(icbcverifySms,ConstantValue.RequestKey.verifySms);
    }
}
